//
//  BN_CreateContentViewController.m
//  BabyNow
//
//  Created by 刘泽琛 on 14-4-15.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_CreateContentViewController.h"

#define content_height 120
#define title_height 35

@interface BN_CreateContentViewController () <UIActionSheetDelegate,UINavigationControllerDelegate,UIAlertViewDelegate,ZYQAssetPickerControllerDelegate> {
    BN_DynamicHelper *dynamicHelper_;
    BN_NoticeHelper *noticeHelper_;
    BN_KinderGartenHelper *kinderHelper_;
    ZYQAssetPickerController *picker_;
}

- (void)realseResource;

@end

@implementation BN_CreateContentViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark
#pragma mark UI

- (void)toHintMessage:(PostSuccessHintMessage)successMessage {
    self.successMessage = successMessage;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // UI+64
    if (IOS7) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"创建内容";
    
    // textView PlaceHolder
    self.textView.placeholder = @"  写点什么吧...";
    self.textView.scrollEnabled = YES;
    self.titleView.placeholder = @"  标题";
    self.titleView.hidden = YES;
    
    UIBarButtonItem *fabuBtn = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(fabuBtnAction)];
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"houtui"] style:UIBarButtonItemStylePlain target:self action:@selector(backViewController)];
    self.navigationItem.leftBarButtonItem = backBtn;
    self.navigationItem.rightBarButtonItem = fabuBtn;
        
    // 类似QQ添加图片
    self.addPicView = [[[NSBundle mainBundle]loadNibNamed:@"IMB_AddPicView" owner:nil options:nil]objectAtIndex:0];
    switch (MAIN_VERSION) {
        case 6:
            self.titleView.frame = CGRectMake(0, 0, SCREEN_WIDTH, title_height);
            self.textView.frame = CGRectMake(0, 0, SCREEN_WIDTH, content_height);
            self.addPicView.frame = CGRectMake(0, content_height+10, 320, 81);
            self.addPicView.minY = content_height+10;
            self.titleView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 35);
            break;
        default:
            self.titleView.frame = CGRectMake(0, 64, SCREEN_WIDTH, title_height);
            self.addPicView.frame = CGRectMake(0, 64+content_height+10, 320, 81);
            self.addPicView.minY = 64+content_height+10;
            break;
    }
    __weak typeof(self) weakSelf = self;
    [self.addPicView backUIImage:^(NSMutableArray *arr) {
        weakSelf.imgsArray = arr;
    }];
    
    [self.addPicView selectTakePhotoOrCamera:^(BOOL isTakePhoto) {
        if (isTakePhoto) {
            [weakSelf.titleView resignFirstResponder];
            [weakSelf.textView resignFirstResponder];
            [weakSelf takePhotoOrcameraAction];
        }
    }];
    
    // 此处检察是家长过来的还是班级过来的
    // fileType = 0 参数是否为视频
    NSUserDefaults *userD = [NSUserDefaults standardUserDefaults];
    NSInteger classParent = [userD integerForKey:USERDEFAULTS_CLASSPARENT];
    if (classParent == 0 && self.cameraAffirmDic) {
        if ([self.cameraAffirmDic[@"fileType"] isEqualToString:@"0"]) {
            self.isVideo = YES;
        }else {
            self.isVideo = NO;
        }
        [self.addPicView cameraAffirm:self.cameraAffirmDic];
    }
    [self.view addSubview:self.addPicView];
        
    // self 点击 键盘消失
    UITapGestureRecognizer *tapGestureR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keyboardHide)];
    [self.view addGestureRecognizer:tapGestureR];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidShow:)
                                                 name:UIKeyboardDidShowNotification
                                               object:nil];
    
    // 是否动态或通知
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    self.dynamicOrNotice = [userDefaults integerForKey:USERDEFAULTS_DYNAMICORNOTICE];
    switch (self.dynamicOrNotice) {
        case 1:
            [self addTitleView];
            break;
        default:
            break;
    }
    
    // helper
    dynamicHelper_ = [[BN_DynamicHelper alloc]init];
    noticeHelper_ = [[BN_NoticeHelper alloc]init];
    kinderHelper_ = [[BN_KinderGartenHelper alloc]init];
    
    // 幼儿园版块
    NSInteger kinderSchoolSection = [[NSUserDefaults standardUserDefaults] integerForKey:USERDEFAULTS_KINDERSECTION];
    switch (kinderSchoolSection) {
        case 1:
            [self addTitleView];
            break;
        case 3:
            [self addTitleViewAndRemovePicView];
            break;
        default:
            break;
    }
}

- (void)addTitleView {
    
    switch (MAIN_VERSION) {
        case 6:
            _titleView.hidden = NO;
            _titleView.frame = CGRectMake(0, 0, SCREEN_WIDTH, title_height);
            _textView.frame = CGRectMake(0, CGRectGetMaxY(_titleView.frame)+10, SCREEN_WIDTH, content_height);
            _addPicView.frame = CGRectMake(0, CGRectGetMaxY(_textView.frame)+10, 320, 81);
            _addPicView.minY = CGRectGetMaxY(_textView.frame)+10;
            break;
        default:
        
            _addPicView.frame = CGRectMake(0, 175+64, 320, 81);
            _addPicView.minY = 175+64;
            _titleView.hidden = NO;
            _titleView.frame = CGRectMake(0, 64, SCREEN_WIDTH, title_height);
            _textView.frame = CGRectMake(0, 64+35+10, SCREEN_WIDTH, content_height);
            break;
    }
}

- (void)addTitleViewAndRemovePicView {
    self.titleView.hidden = NO;
    
    switch (MAIN_VERSION) {
        case 6:
            self.titleView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 35);
            break;
        default:
            self.titleView.frame = CGRectMake(0, 64, SCREEN_WIDTH, 35);
            break;
    }
    self.titleView.hidden = NO;
    switch (MAIN_VERSION) {
        case 6:
            self.textView.frame = CGRectMake(0, 45, SCREEN_WIDTH, content_height);
            break;
        default:
            self.textView.frame = CGRectMake(0, 64+35+10, SCREEN_WIDTH, content_height);

            break;
    }
    [self.addPicView removeFromSuperview];
}


#pragma mark
#pragma mark Action

- (void)takePhotoOrcameraAction {
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:nil
                                  delegate:self
                                  cancelButtonTitle:@"取消"
                                  destructiveButtonTitle:nil
                                  otherButtonTitles:@"拍照", @"从相册选择",nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view];
}

// 调用相册
- (void)presentVC:(NSNotification *)notification {
    id result = notification.object;
    if (self.presentedViewController == nil)
    {
        [self.navigationController presentViewController:result animated:YES completion:NULL];
    }
}

- (id)getCurNavController{
    UINavigationController* navController = (UINavigationController*)self.tabBarController.selectedViewController;
    return navController;
}

// 返回上级控制器
- (void)backViewController {
    
    if ([_textView.text isEqualToString:@"  写点什么吧..."] && [_titleView.text isEqual:@"  标题"] && self.imgsArray.count <= 0) {
        [self exitVc];
    }else {
        UIAlertView *backVcAlertView = [[UIAlertView alloc]initWithTitle:nil message:@"确定放弃编辑的内容？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        backVcAlertView.tag = 180;
        [backVcAlertView show];
    }
}

- (void)exitVc {
    [self realseResource];
    [self.navigationController popViewControllerAnimated:YES];
}

// 发布
- (void)fabuBtnAction {

    [SVProgressHUD showWithStatus:@"正在准备上传..." maskType:SVProgressHUDMaskTypeBlack];
    
    // __weak属性随时释放
    __weak typeof (self) weakSelf = self;

    // 取消键盘
    [self.textView resignFirstResponder];
    [self.titleView resignFirstResponder];
    
    NSString *receiveType = [NSString stringWithFormat:@"%@",self.cameraAffirmDic[@"fileType"]];
    NSArray *fileInfoArr = nil;
    
    // 判断是发布班级动态 或 家长动态
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSInteger isClassParent = [userDefault integerForKey:USERDEFAULTS_CLASSPARENT];
    ENUM_DYNAIMC_TYPE section;
    
    switch (isClassParent) {
        case 0:
        {
            section = ENUM_DYNAIMC_FOR_CLASS;
            
            // 上传视频
            if ([receiveType isEqualToString:@"0"]) {
                NSData *videoData = self.cameraAffirmDic[@"fileData"];
                NSString *videoName = @"video.mp4";
                // 缩略图
                UIImage *sltImg = self.cameraAffirmDic[@"fileImg"][0];
                NSData *sltData = UIImagePNGRepresentation(sltImg);
                fileInfoArr = @[
                                @{kFileName:@"video.png",kFileData:sltData,kFileMimeType:FILE_MIME_TYPE_FOR_PNG},
                                @{kFileName:videoName,kFileData:videoData,kFileMimeType:FILE_MIME_TYPE_FOR_MP4}
                                ];
            }
            // 上传图片
            if ([receiveType isEqualToString:@"1"]) {
                fileInfoArr = [[NSMutableArray alloc]init];
                NSMutableArray *addArr = [[NSMutableArray alloc]init];
                NSDictionary *addDict = [[NSDictionary alloc]init];
                for (int i = 0; i < self.imgsArray.count; i++) {
                    UIImage *image = self.imgsArray[i];
                    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
                    NSString *imgName = [NSString stringWithFormat:@"%d.png",i];
                    
                    addDict = @{kFileName: imgName,kFileData: imageData,kFileMimeType:FILE_MIME_TYPE_FOR_PNG};
                    [addArr addObject:addDict];
                }
                fileInfoArr = addArr;
            }
        }
            break;
        case 1:
        {
            section = ENUM_DYNAIMC_FOR_PARENT;
            
            fileInfoArr = [[NSMutableArray alloc]init];
            NSMutableArray *addArr = [[NSMutableArray alloc]init];
            NSDictionary *addDict = [[NSDictionary alloc]init];
            for (int i = 0; i < self.imgsArray.count; i++) {
                UIImage *image = self.imgsArray[i];
                NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
                NSString *imgName = [NSString stringWithFormat:@"%d.png",i];
                
                addDict = @{kFileName: imgName,kFileData: imageData,kFileMimeType:FILE_MIME_TYPE_FOR_PNG};
                [addArr addObject:addDict];
            }
            fileInfoArr = addArr;
        }
            break;
        default:
            fileInfoArr = [[NSMutableArray alloc]init];
            NSMutableArray *addArr = [[NSMutableArray alloc]init];
            NSDictionary *addDict = [[NSDictionary alloc]init];
            for (int i = 0; i < self.imgsArray.count; i++) {
                UIImage *image = self.imgsArray[i];
                NSData *imageData = UIImageJPEGRepresentation(image, 0.4);
                NSString *imgName = [NSString stringWithFormat:@"%d.png",i];
                
                addDict = @{kFileName: imgName,kFileData: imageData,kFileMimeType:FILE_MIME_TYPE_FOR_PNG};
                [addArr addObject:addDict];
            }
            fileInfoArr = addArr;
            break;
    }
    
    // 得到文本，去掉两端空格
    NSString *postSubj = [self.titleView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([postSubj isEqualToString:@"标题"]) {
        postSubj = @"";
    }
    
    NSString *postCont = [self.textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([postCont isEqualToString:@"写点什么吧..."]) {
        postCont = @"";
    }
    
    switch (self.dynamicOrNotice) {
        case 0:
            {
            // 判断有没有图片或视频
                if (fileInfoArr.count <= 0) { // isClassParent == 0
                    [LZCHINT title:@"请选择图片" type:LZCInfo duration:2 places:HINT_PLACES callBack:NULL];
                    [SVProgressHUD dismiss];
                    return;
                }
            [dynamicHelper_ postDynamicWithSubj:postCont postType:section filesInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
                if (errMsg) {
                    [SVProgressHUD dismiss];
                    [LZCHINT title:errMsg type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
                }else{
                    [SVProgressHUD dismiss];
                    // 上传成功，列表刷新
                    switch (isClassParent) {
                        case 0:
                            [[NSNotificationCenter defaultCenter]postNotificationName:KCLASSAUTOREFRESH object:@"isScrollToTop"];
                            break;
                        case 1:
                            [[NSNotificationCenter defaultCenter]postNotificationName:KPARENTAUTOREFRESH object:@"isScrollToTop"];
                            break;
                        default:
                            break;
                    }
                    weakSelf.successMessage(YES);
                    [weakSelf realseResource];
                    [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                }
            } uploadProcessingHandler:^(double process) {
                [SVProgressHUD showProgress:process status:@"上传中..." maskType:SVProgressHUDMaskTypeBlack];
                NSLog(@"动态上传进度...%f",process);
            }];
            }
            break;
        case 1:
            {
                if (postCont.length <= 0 && fileInfoArr.count <= 0) {
                    [LZCHINT title:@"请选择图片" type:LZCInfo duration:2 places:HINT_PLACES callBack:NULL];
                    [SVProgressHUD dismiss];
                    return;
                }
                [noticeHelper_ postNoticeWithSubject:postSubj content:postCont fileInfoArr:fileInfoArr completeHandler:^(id result,NSString *errMsg) {
                if (errMsg) {
                    [SVProgressHUD dismiss];
                    [LZCHINT title:errMsg type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
                }else{
                    [SVProgressHUD dismiss];
                    [[NSNotificationCenter defaultCenter]postNotificationName:KREFRESH_NOTICELIST object:@"isScrollToTop"];
                    weakSelf.successMessage(YES);
                    [weakSelf realseResource];
                    [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                }
            } uploadProcessingHandler:^(double process) {
                [SVProgressHUD showProgress:process status:@"上传中..." maskType:SVProgressHUDMaskTypeBlack];
                NSLog(@"通知上传进度...%f",process);
            }];

            }
            break;
        default:
            break;
    }
    
    // 幼儿园4个版块
    NSInteger kinderSchoolSection = [[NSUserDefaults standardUserDefaults] integerForKey:USERDEFAULTS_KINDERSECTION];
    switch (kinderSchoolSection) {
        case 0:
        {
            if (fileInfoArr.count <= 0) {
                [LZCHINT title:@"请选择图片" type:LZCInfo duration:2 places:HINT_PLACES callBack:NULL];
                [SVProgressHUD dismiss];
                return;
            }
            [kinderHelper_ sendKgInfoWithBrieCont:postCont fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
                if (result) {
                    [SVProgressHUD dismiss];
                    [[NSNotificationCenter defaultCenter]postNotificationName:KSENDSUCCESS_AFTER_JIANJIE_REFRESH object:@"isScrollToTop"];
                    weakSelf.successMessage(YES);
                    [weakSelf realseResource];
                    [weakSelf.navigationController popViewControllerAnimated:YES];
                }else{
                    [SVProgressHUD dismiss];
                    [LZCHINT title:errMsg type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
                }
            } uploadProcessingHandler:^(double process) {
                [SVProgressHUD showProgress:process status:@"上传中..." maskType:SVProgressHUDMaskTypeBlack];
                NSLog(@"幼儿园简介上传进度...%f",process);
            }];
        }
            break;
        case 1:
        {
            if (postCont.length <= 0 && fileInfoArr.count <= 0) {
                [LZCHINT title:@"请选择图片或填写信息" type:LZCInfo duration:2 places:HINT_PLACES callBack:NULL];
                [SVProgressHUD dismiss];
                return;
            }
            
            [kinderHelper_ sendActionNotiSubj:postSubj notiCont:postCont fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
                if (result) {
                    [SVProgressHUD dismiss];
                    [[NSNotificationCenter defaultCenter]postNotificationName:KSENDSUCCESS_AFTER_ACTIVITY_REFRESH object:@"isScrollToTop"];
                    weakSelf.successMessage(YES);
                    [weakSelf realseResource];
                    [weakSelf.navigationController popViewControllerAnimated:YES];
                }else{
                    [SVProgressHUD dismiss];
                    [LZCHINT title:errMsg type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
                }

            } uploadProcessingHandler:^(double process) {
                [SVProgressHUD showProgress:process status:@"上传中..." maskType:SVProgressHUDMaskTypeBlack];
                NSLog(@"活动上传进度...%f",process);

            }];
        }
            break;
        case 2:
        {
            if (postCont.length <= 0 && fileInfoArr.count <= 0) {
                [LZCHINT title:@"请选择图片或填写信息" type:LZCInfo duration:2 places:HINT_PLACES callBack:NULL];
                [SVProgressHUD dismiss];
                return;
            }
            [kinderHelper_ sendFoodNotiSubj:postSubj notiCont:postCont fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
                if (result) {
                    [SVProgressHUD dismiss];
                    [[NSNotificationCenter defaultCenter]postNotificationName:KSENDSUCCESS_AFTER_FOOD_REFRESH object:@"isScrollToTop"];
                    weakSelf.successMessage(YES);
                    [weakSelf realseResource];
                    [weakSelf.navigationController popViewControllerAnimated:YES];
                }else{
                    [SVProgressHUD dismiss];
                    [LZCHINT title:errMsg type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
                }

            } uploadProcessingHandler:^(double process) {
                [SVProgressHUD showProgress:process status:@"上传中..." maskType:SVProgressHUDMaskTypeBlack];
                NSLog(@"美食上传进度...%f",process);
            }];
        }
            break;
        case 3:
        {
            if (postCont.length <= 0 && fileInfoArr.count <= 0) {
                [LZCHINT title:@"请选择图片或填写信息" type:LZCInfo duration:2 places:HINT_PLACES callBack:NULL];
                [SVProgressHUD dismiss];
                return;
            }
            [kinderHelper_ sendSuggestInfoWithSuggSubj:postSubj SuggCont:postCont fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
                if (result) {
                    [SVProgressHUD dismiss];
                    [[NSNotificationCenter defaultCenter]postNotificationName:KSENDSUCCESS_AFTER_SUGGEST_REFRESH object:@"isScrollToTop"];
                    weakSelf.successMessage(YES);
                    [weakSelf realseResource];
                    [weakSelf.navigationController popViewControllerAnimated:YES];
                }else{
                    [SVProgressHUD dismiss];
                    [LZCHINT title:errMsg type:LZCError duration:2 places:HINT_PLACES callBack:NULL];
                }
            } uploadProcessingHandler:^(double process) {
                [SVProgressHUD showProgress:process status:@"上传中..." maskType:SVProgressHUDMaskTypeBlack];
                NSLog(@"信箱上传进度...%f",process);
            }];
        }
            break;
        default:
            break;
    }
}

- (void)keyboardDidShow:(NSNotification *)aNotification {
    /*
    NSDictionary *info = [aNotification userInfo];
    NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    NSString *height = [NSString stringWithFormat:@"%f",keyboardRect.size.height];
    NSInteger heightValue = [height integerValue];*/
}

- (void)keyboardHide {
    [self.textView resignFirstResponder];
}

#pragma mark
#pragma mark Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // [self.textView resignFirstResponder];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        // 拍照
        BN_TakePhotoController *takePhotoVCtrl = [[BN_TakePhotoController alloc]init];
        [takePhotoVCtrl getTodealWith:^(UIImage *img) {
            [self.addPicView createPageSendImg:img];
                     }];
        [self.navigationController presentViewController:takePhotoVCtrl animated:YES completion:nil];
    }else if (buttonIndex == 1) {
        // 相册选择
        [self openCameraAction];
        
    }else if(buttonIndex == 2) {
        // 取消
    }
}

#pragma mark
#pragma mark 打开相册
- (void)openCameraAction {
    
// 判断哪个版块，动态最多9张，其余1张
    picker_ = [[ZYQAssetPickerController alloc] init];
    if ([[NSUserDefaults standardUserDefaults]integerForKey:USERDEFAULTS_CLASSPARENT] == 10) {
        picker_.maximumNumberOfSelection = 2;
    }else {
        picker_.maximumNumberOfSelection = 10;
    }
    picker_.assetsFilter = [ALAssetsFilter allPhotos];
    picker_.showEmptyGroups = NO;
    picker_.delegate = self;
    picker_.selectionFilter = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
        if ([[(ALAsset*)evaluatedObject valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypeVideo]) {
            NSTimeInterval duration = [[(ALAsset*)evaluatedObject valueForProperty:ALAssetPropertyDuration] doubleValue];
            return duration >= 5;
        } else {
            return YES;
        }
    }];
    [self presentViewController:picker_ animated:YES completion:NULL];
}

-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // src.contentSize = CGSizeMake(assets.count*src.frame.size.width, src.frame.size.height);
        dispatch_async(dispatch_get_main_queue(), ^{
            // pageControl.numberOfPages = assets.count;
        });
        
        for (int i=0; i<assets.count; i++) {
            ALAsset *asset=assets[i];
            UIImage *tempImg = [UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
            dispatch_async(dispatch_get_main_queue(), ^{
                // 得到上面图片后，block回调 相应的方法
                [self.addPicView createPageSendImg:tempImg];
            });
        }
    });
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 180) {
        if (buttonIndex == 1) {
            [self exitVc];// 退出创建内容
        }
    }
}

#pragma mark
#pragma mark 释放资源
- (void)realseResource {
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KCLASSAUTOREFRESH object:@"isScrollToTop"];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KREFRESH_NOTICELIST object:@"isScrollToTop"];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KSENDSUCCESS_AFTER_JIANJIE_REFRESH object:@"isScrollToTop"];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KSENDSUCCESS_AFTER_FOOD_REFRESH object:@"isScrollToTop"];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KSENDSUCCESS_AFTER_ACTIVITY_REFRESH object:@"isScrollToTop"];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KSENDSUCCESS_AFTER_SUGGEST_REFRESH object:@"isScrollToTop"];
    
    self.imgsArray = nil;

    picker_.delegate = nil;
    picker_ = nil;
    
    dynamicHelper_ = nil;
    noticeHelper_ = nil;
    kinderHelper_ = nil;
    
    self.addPicView.delegate = nil;
    self.addPicView.backImgs = nil;
    self.addPicView.isTakePhoto = nil;
    self.addPicView = nil;
        
    self.titleView.delegate = nil;
    self.textView.delegate = nil;
    self.titleView = nil;
    self.textView = nil;
    
    self.successMessage = nil;
}

- (void)dealloc
{
    [self realseResource];
    NSLog(@"创建内容页 释放 ...");
}

@end
